package org.example.bookssystem.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完没注意的速成派
 * User: XALEXC
 * Date: 2024-10-23
 * Time: 11:18
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @RequestMapping("/login")
    public Boolean login(String userName, String passWord, HttpSession session) {

        //校验参数
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(passWord)) {
            return false;
        }
        // 验证账号密码是否正确
        if("admin".equals(userName)&&"admin".equals(passWord)){
            // 密码正确
            // 存Session
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }
}
